package kr.co.exight.onApp;

import library.DialogChoiceYesNo;
import library.Library;
import library.Library.DialogChoiceYes;
import android.app.Activity;
import android.app.LocalActivityManager;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;


/** Called when the activity is first created. */
public class ActivityMain extends Activity implements OnClickListener {
	
	private final static int BTN_NOTICE = R.id.main_btnNotice;
	private final static int BTN_FACEBOOK = R.id.main_btnFacebook;
	private final static int BTN_ASK = R.id.main_btnAsk;
	
	private final static int BTN_DELIVERY = R.id.main_btnDelievery;
	private final static int BTN_ONCARD = R.id.main_btnOncard;
	private final static int BTN_ONTIME = R.id.main_btnOntime;
	
	private final static int BTN_HOME = R.id.main_btnHome;
	private final static int BTN_SHUTTLE = R.id.main_btnShuttle;
	private final static int BTN_MAP = R.id.main_btnMap;
	
	private final static int BTN_LIBRARY = R.id.main_btnLibrary;
	private final static int BTN_YSCEC = R.id.main_btnYscec;
	private final static int BTN_TIMETABLE = R.id.main_btnTimetable;
	
	private final static int BTN_PREFERENCE = R.id.main_btnPref;

	int countFlag = 0;
	
	public static Activity mainActivity;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.act_main);

		mainActivity = this;
		
		findViewById(BTN_NOTICE).setOnClickListener(this);
		findViewById(BTN_FACEBOOK).setOnClickListener(this);
		findViewById(BTN_ASK).setOnClickListener(this);
		findViewById(BTN_DELIVERY).setOnClickListener(this);
		findViewById(BTN_ONCARD).setOnClickListener(this);
		findViewById(BTN_ONTIME).setOnClickListener(this);
		findViewById(BTN_HOME).setOnClickListener(this);
		findViewById(BTN_SHUTTLE).setOnClickListener(this);
		findViewById(BTN_MAP).setOnClickListener(this);
		findViewById(BTN_LIBRARY).setOnClickListener(this);

		findViewById(BTN_PREFERENCE).setOnClickListener(this);
		
		findViewById(BTN_YSCEC).setOnClickListener(this);  
		findViewById(BTN_TIMETABLE).setOnClickListener(this);
		
		Library.setFontNanumGothic((TextView)findViewById(R.id.main_tvAsk));
		Library.setFontNanumGothic((TextView)findViewById(R.id.main_tvBus));
		Library.setFontNanumGothic((TextView)findViewById(R.id.main_tvDelievery));
		
		Library.setFontNanumGothic((TextView)findViewById(R.id.main_tvFacebook));
		Library.setFontNanumGothic((TextView)findViewById(R.id.main_tvHome));
		Library.setFontNanumGothic((TextView)findViewById(R.id.main_tvLibrary));
		
		Library.setFontNanumGothic((TextView)findViewById(R.id.main_tvMap));
		Library.setFontNanumGothic((TextView)findViewById(R.id.main_tvNotice));
		Library.setFontNanumGothic((TextView)findViewById(R.id.main_tvOncard));
		
		Library.setFontNanumGothic((TextView)findViewById(R.id.main_tvOntime));
		Library.setFontNanumGothic((TextView)findViewById(R.id.main_tvTimetable));
		Library.setFontNanumGothic((TextView)findViewById(R.id.main_tvYscec));

	}
	@Override
	public void onBackPressed() {
		// TODO Auto-generated method stub
		countFlag++;
		if(countFlag == 2){
			Library.makeYesNoDialog(this, "ONApp을 종료하시겠습니까?", "확인", "취소", new Library.DialogChoiceYesNo() {
				
				public boolean choiceYes() {
					
					// TODO Auto-generated method stub
					finish();
					return false;
				}
				
				public boolean choiceNo() {
					// TODO Auto-generated method stub
					countFlag = 0;
					return false;
				}
			});
		}
	     
	}

	public void onClick(View v) {
		// TODO Auto-generated method stub
		Intent i  = null;
		
		switch(v.getId()){

		case BTN_NOTICE:
			i = new Intent(this, ActivityWebView.class).putExtra("KEY", 1);
			break;

		case BTN_FACEBOOK:
			i = new Intent(this, ActivityWebView.class).putExtra("KEY", 2);
			break;

		case BTN_ONCARD:
			i = new Intent(this, ActivityTabOncard.class).putExtra("MODE", 0);
			break;

		case BTN_ONTIME:
			//i= null;
			i = new Intent(this, ActivityTabOncard.class).putExtra("MODE", 1);
			break;

		case BTN_HOME:
			i = new Intent(this, ActivityHouse.class);
			break;

		case BTN_SHUTTLE:
			i = new Intent(this, ActivityShuttle.class);
			break;

		case BTN_MAP:
			i = new Intent(this, ActivityMap.class);
			break;

		case BTN_LIBRARY:
			i = new Intent(this, ActivityLibrary.class);
			break;

		case BTN_YSCEC:
			i = new Intent(this, ActivityYscec.class);
			break;

		case BTN_TIMETABLE:
			i = new Intent(this, ActivityTimeTable.class);
			break;

		case BTN_ASK:
			i = new Intent(this, ActivityWebView.class).putExtra("KEY", 6);
			break;

			//��ɹ�ư
		case BTN_DELIVERY:
			i = new Intent(this, ActivityDelivery.class);
			break;
		case BTN_PREFERENCE:
			i= new Intent(this, ActivityPreference.class);
			break;
		}
		
		if(i == null){
			Library.makeYesDialog(ActivityMain.this, "준비중입니다.", "확인", new DialogChoiceYes() {
				
				public boolean choiceYes() {
					// TODO Auto-generated method stub
					return false;
				}
			});
		}else {

			startActivity(i);
			
		}
	}
}